import React from 'react';
//  npm i prop-types:做props数据类型验证
import PropTypes from 'prop-types';
class Father extends React.Component{
    state={
        arr:[1,2,3],
        person:{
            name:"李四",
            age:19,
            // height:190
        }
    }
    render(){
        return <div>
            <h1>父组件</h1>
            <Child userAge={99} list={this.state.arr} obj={this.state.person}></Child>
        </div>
    }
}

class Child extends React.Component{
    render(){
        console.log(this.props);
        return <div>
            <h2>子组件</h2>
            <p>父组件传给子组件的值：{this.props.userAge}----{this.props.userName}</p>

            {/* <ul>
                {this.props.children.map((item,index)=><li key={index}>{item}</li>)}
            </ul> */}

            
        </div>
    }
}

// 类型验证
Child.propTypes ={
    userAge:PropTypes.number,
    list:PropTypes.array,
    obj:PropTypes.shape({
        name:PropTypes.string.isRequired,
        age:PropTypes.number.isRequired
    })

}
// 默认值
Child.defaultProps={
    userAge:10
}



export default Father


